package sanshi.contect.proxy.v2;

import java.util.Random;

public class Tank implements Movable {
    @Override
    public void move() {
        System.out.println("tank moving calcalfldlslas-------");
        try {
            Thread.sleep(new Random().nextInt(10000));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

interface Movable{
    void move();
}

/**
 * 代理模式(聚合的方式)
 * tank move time :9856ms
 */
class TankTimeProxy implements Movable{

    Movable movable;

    public TankTimeProxy(Movable movable) {
        this.movable = movable;
    }

    @Override
    public void move() {
        long startTime  = System.currentTimeMillis();
        movable.move();
        long endTime = System.currentTimeMillis();
        System.out.println("tank move time :" + (endTime - startTime) + "ms");
    }
}

class TankLogProxy implements Movable{

    Movable movable;

    public TankLogProxy(Movable movable) {
        this.movable = movable;
    }
    @Override
    public void move() {
        System.out.println("tank start move....");
        movable.move();
        System.out.println("tank end move......");

    }
}